<include file="_header" />
<script type="text/javascript">
    var array = new Array();
    <php>foreach($widget as $key=>$value){</php>
        array[{$key}] = '{$value['explain']}';
    <php>}</php>
    var widgetField = new Array();
    <php>foreach($fields as $key=>$value){</php>
    widgetField['{$key}'] = new Array();
    <php>foreach($value as $sokey=>$sovalue){</php>
    widgetField['{$key}'][{$sokey}] = '{$sovalue}';
    <php>}</php>
    <php>}</php>
    var oldField = new Array();
    var temp_text = "";
    $(function(){
        temp_text = $('#explain').text();
        $('#explain').text($('#explain').text()+":"+array[0]);
    })
    function change(key){
        $('#explain').text(temp_text+":"+array[key]);
    }
    function changeWidget(selectedId,id){
        var field = $('select option[value='+selectedId+']').attr('rel');
        

        	$("select[id!="+id+"][name*='extra']").each(function(){
      		 for(var i=0;i<widgetField[field].length;i++){
          		 $('#'+this.id+' option[value='+widgetField[field][i]+']').remove("");
       		 }
        	});
         
    }        
</script>
<script>
function checkAdd(){
	var name = $("#name").val();
	var data = $("#data").val();
	if(!name || getLength(name.replace(/\s+/g,"")) == 0){
		ui.error("请输入属性名");
		$("#name").focus();
		return false;
	}else if(getLength($("#name").val()) > 6){
		ui.error("属性名不得大于6个字");
		$("#name").focus();
		return false;
	}else if(!data || getLength(data.replace(/\s+/g,"")) == 0){
		ui.error("渲染器数据不能为空");
		$("#data").focus();
		return false;
	}
	
}

</script>

  <div id="container" class="so_main">
    <include file="_tab" />
      <div class="tit_tab" style="background-color:#E7E8FF;">
        <ul>
          <li><a href="__URL__&act=add" <if condition="$_GET['action'] neq 'extra' && $_GET['action'] neq 'smallType'">class="on"</if>>增加大分类</a></li>
          <li><a href="__URL__&act=add&action=extra" <if condition="$_GET['action'] eq 'extra'">class="on"</if>>添加大分类额外属性</a></li>
          <li><a href="__URL__&act=add&action=smallType" <if condition="$_GET['action'] eq 'smallType'">class="on"</if>>增加二级分类</a></li>
        </ul>
      </div>
      <if condition="$_GET['action'] eq 'extra'">
      <form action = "__URL__&act=doAddWidget" method="post" onsubmit="return checkAdd();">
        <div class="form2 no_line">
          <dl class="lineD">
            <dt>属性名：</dt>
            <dd>              
              <input name="name" class="txt" id="name"/>
              <p>额外属性名。</p>
            </dd>
          </dl>
          <dl class="lineD">
            <dt>选择渲染器：</dt>
            <dd>              
              <select name="widget">
                <volist name="widget" k="key" id="vo">
                  <option value="{$vo['value']}" onclick="change({$key})">{$vo['name']}</option>
                </volist>
              </select>
              <p>渲染器是每一种输入方式的渲染工具文件。html代码将直接写在这些文件里面。文件在应用的Lib/Widget/下。</p>
            </dd>
          </dl>
          <dl class="lineD">
            <dt>渲染器数据：</dt>
            <dd>              
              <textarea name="data" class="txt" cols="30" rows="10" id="data"></textarea>
              <p>对以上渲染器的数据进行填写。</p>
            </dd>
          </dl>
          <dl class="lineD">
            <dt>数据库字段选择：</dt>
            <dd>              
              <select name="field">
              <php>for($i=1;$i<6;$i++){</php>
                <option value="extra{$i}">额外字段{$i}</option>
              <php>}</php>
              </select>
              <p>数据存储的数据库存储字段。注意：当每个应用启用的数据库额外字段不能重复。</p>
            </dd>
          </dl>
          <div class="page_btm">
            <input type="submit" class="btn_b" value="确定" />
          </div>
        </div>
      </form>
      <elseif condition="$_GET['action'] eq 'smallType'" />
      <form action = "__URL__&act=doAddSmallType" method="post" onsubmit="return checkSmallType();">
        <div class="form2 no_line">
          <dl class="lineD">
            <dt>小分类集合名：</dt>
            <dd>              
              <input name="name" class="txt" id="name"/>
            </dd>
          </dl>
          <dl>
            <dt>小分类项：</dt>
            <dd>              
              <textarea name="data" class="txt" cols="30" rows="10" id="data"></textarea>
              <p>即集合内的各个小分类选项( 小分类名之间换行隔开)。</p>
            </dd>
          </dl>
          <div class="page_btm">
            <input type="submit" class="btn_b" value="确定" />
          </div>
        </div>
      </form>
      <else />
      <form action = "__URL__&act=doAddType" method="post" onsubmit="return checkType();">
        <div class="form2 no_line">
          <dl class="lineD">
            <dt>分类名：</dt>
            <dd>              
              <input name="name" class="txt" id="name" maxlength="40"/>
              <p>填写在前台显示的{$ts['app']['app_alias']}大分类：如招聘，物品交换。</p>
            </dd>
          </dl>
          <dl class="lineD">
            <dt>图标：</dt>
            <dd>
              <div style="width:420px;">
              <volist name="ico" id="vo">
                <input type="radio" name="ico" value="{$vo}" style="margin-bottom:15px;" /><img src="{$icopath}{$vo}" />
              </volist>
              </div>
              <p>分类所使用的图标。存放在应用的images/ico下。注意图片不要太大。</p>
            </dd>
          </dl>
          <dl class="lineD">
            <dt>描述：</dt>
            <dd>              
              <textarea name="explain" class="txt" cols="44" rows="8" id="exp"></textarea>
              <p>填写对这个分类的描述。会在前台显示。</p>
            </dd>
          </dl>
          <div class="page_btm">
            <input type="submit" class="btn_b" value="确定" />
          </div>
        </div>
      </form>
      </if>
  </div>
<script>
function checkType(){
  var name = $("#name").val();
  var explain = $("#exp").val();
  if (!name || getLength(name.replace(/\s+/g,"")) == 0) {
	ui.error("分类名称不能为空");
	$("#name").focus();
	return false;
  }
  if (getLength($("#name").val()) > 20){
	ui.error("分类名称不得大于40个字符");
	$("#name").focus();
	return false;
  }
  if (!explain || getLength(explain.replace(/\s+/g,"")) == 0) {
	ui.error("描述不能为空");
	$("#explain").focus();
	return false;
  }
  
}
function checkSmallType(){
	var name = $("#name").val();
	var explain = $("#data").val();
	if (!name || getLength(name.replace(/\s+/g,"")) == 0) {
		ui.error("小分类集合名称不能为空");
		$("#name").focus();
		return false;
	}
	if (getLength($("#name").val()) > 20){
		ui.error("小分类集合名称不得大于40个字符");
		$("#name").focus();
		return false;
	}
	if (!explain || getLength(explain.replace(/\s+/g,"")) == 0) {
		ui.error("小分类项不能为空");
		$("#data").focus();
		return false;
	}
}
</script>
<include file="_footer" />
